package ar.edu.utn.frsf.proyectofinal.sistemadecontrolmodbus.presentation.controller.admin.devtypes;

import java.util.ArrayList;
import java.util.List;

import ar.edu.utn.frsf.proyectofinal.sistemadecontrolmodbus.persistence.model.AddressType;
import ar.edu.utn.frsf.proyectofinal.sistemadecontrolmodbus.persistence.model.Field;

public class FieldBean {
	//name address type bittype bitnummber
	Field field;

	public FieldBean(Field field) {
		this.field = field;
	}
	
	public Integer getHash(){
		return field.hashCode();
	}
	
	public Field getField() {
		return field;
	}

	public void setField(Field field) {
		this.field = field;
	}
	
	public String getName(){
		return field.getName();
	}
	
	public void setName(String name){
		 field.setName(name);
	}
	
	public Integer getAddress(){
		return field.getAddress();
	}
	
	public void setAddress(Integer address){
		 field.setAddress(address);
	}
	
	public AddressType getType(){
		return field.getAddressType();
	}
	
	public void setType(AddressType type){
		field.setAddressType(type);
		System.out.println("Setting Field Type: " + type);
	}
	
	public boolean getBittype(){
		return field.getBitType();
	}
	
	public void setBittype(boolean value){
		field.setBitType(new Boolean(value));
		System.out.println("Setting BitType: " + value);
	}
	
	public Integer getBitnummber(){
		return field.getBitOffset();
	}
	
	public void setBitnummber(Integer value){
		field.setBitOffset(value);
		System.out.println("Setting BitOffset: " + value);
	}
	
	public static List<FieldBean> wrap(List<Field> fields) {
		List<FieldBean> ret = new ArrayList<FieldBean>();
		for (Field field : fields) {
			ret.add(new FieldBean(field));
		}
		return ret;
	}
	
	public boolean getDisableBitCheck(){
		AddressType type = field.getAddressType();
		return type == AddressType.COIL || type == AddressType.DISCRETE; 
	}
	
	public boolean getDisableBitOffset(){
		return getDisableBitCheck() || !field.getBitType(); 
	}
}
